package com.bank2.service;

import com.bank2.domain.User;
import com.bank2.mapper.User2Mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@DubboService
@Service
public class Bank2Service implements Bank2Interface{
    @Autowired
    private User2Mapper user2Mapper;
    @Override
    public String addAmount(String name,int amount) throws InterruptedException {
        User user=null;
        user = user2Mapper.selectOne(new LambdaQueryWrapper<User>().eq(StringUtils.isEmpty(name), User::getName, name));
        user=null;
        if (user==null){
            Thread.sleep(20000);
            throw new RuntimeException("name为空或用户不存在");
        }
        user.setAmount(user.getAmount()+amount);
        int i = user2Mapper.update(user, new LambdaQueryWrapper<User>().eq(User::getName, name));
        return i>0?"成功":"失败";
    }
}
